<?php

//详细页

namespace app\admin\controller;
use app\model\ArticleModel;
use app\model\CategoryModel;
use think\facade\Request;
use think\facade\Validate;
use think\facade\View;

class Ago{
    //主页
    public function ago_list(){
        $categoryList = CategoryModel::select();
        $category = Request::param() ?? '';
        if(empty($category)){
            $category = 3;
            $result = CategoryModel::limit($category)->select();
            View::assign('result',$result);
        }else{
            $result = CategoryModel::select($category);
            View::assign('result',$result);
        }
        View::assign('categoryList',$categoryList);
        return View::fetch();
    }

    // 详细页
    public function article_list(){
        //存取分类id
        session_start();
        $category = Request::param('category_id');//获取分类id
        if(empty($category)){
            $category = $_SESSION['category'];
        }else{
            $_SESSION['category'] = $category;
        }

        $article = Request::param('article_id') ?? ''; //获取文章id

        //查询分类下文章的总数据
        $articleList = ArticleModel::where('category_id','=',$category)->limit(3)->select();
        //文章下的详细信息
        if(empty($article)){
            $result = ArticleModel::where('category_id','=',$category)->limit(3)->select();
            View::assign('result',$result);
        }else{
            $result = ArticleModel::where('article_id','=',$article)->select();
            View::assign('result',$result);
        }
        //分类下总文章变量
        View::assign('articleList',$articleList);
        return View::fetch();
    }
}